#!/bin/sh
#行程事件表-行程维度 RANGE分区2021-12-31-- 2024-03-20
table_name=app_trip_statistic_event_pdi

create_table_sql=$(cat <<EOF
    DROP TABLE IF EXISTS ${KUDU_DATABASE}.${table_name};
    CREATE TABLE IF NOT EXISTS ${KUDU_DATABASE}.${table_name}(
           tid                    bigint   comment '终端号',
           start_gps_time         bigint   comment '事件开始时间(ms)',
           event                  string   comment '事件类型',
           pdt                    int      COMMENT 'yyyyMMdd 数据时间',
           stype                  int      comment '事件来源类型(1:基于0f37数据来生成的事件 2:根据0200数据来统计的行程)',
           start_latitude         int      comment '事件开始纬度',
           start_longitude        int      comment '事件开始经度',
           start_height           int      comment '事件开始高程',
           start_speed            int      comment '事件开始GPS车速(综合车速)',
           start_gps_direction    int      comment '事件开始GPS方向',
           stop_gps_time          bigint   comment '事件结束时间(ms)',
           stop_latitude          int      comment '事件结束纬度',
           stop_longitude         int      comment '事件结束经度',
           stop_height            int      comment '事件结束高程',
           stop_speed             int      comment '事件结束GPS车速(综合车速)',
           stop_gps_direction     int      comment '事件结速gps方向',
           duration               bigint   comment '事件持续时间(ms)',
           extend_field01         int      comment '扩展数据01',
           extend_field02         int      comment '扩展数据02',
           extend_field03         int      comment '扩展数据03',
           extend_field04         int      comment '扩展数据04',
           extend_field05         double   comment '扩展数据05',
           extend_field06         double   comment '扩展数据06',
           extend_field07         double   comment '扩展数据07',
           extend_field08         double   comment '扩展数据08',
           extend_field09         bigint   comment '扩展数据09',
           extend_field10         bigint   comment '扩展数据10',
           update_time            string   COMMENT '修改时间',
          PRIMARY KEY(tid,start_gps_time,event)
    )PARTITION BY HASH(tid) PARTITIONS 30,
    RANGE (start_gps_time)(
            PARTITION 1640880000000 <= VALUES < 1648656000000,
            PARTITION 1648656000000 <= VALUES < 1656432000000,
            PARTITION 1656432000000 <= VALUES < 1664208000000,
            PARTITION 1664208000000 <= VALUES < 1671984000000,
            PARTITION 1671984000000 <= VALUES < 1679760000000,
            PARTITION 1679760000000 <= VALUES < 1687536000000,
            PARTITION 1687536000000 <= VALUES < 1695312000000,
            PARTITION 1695312000000 <= VALUES < 1703088000000,
            PARTITION 1703088000000 <= VALUES < 1710864000000
)
    STORED AS KUDU
    TBLPROPERTIES (
        'kudu.master_addresses' = '${KUDU_MASTER}',
        'kudu.num_tablet_replicas'='1'
    );
EOF
)

impala-shell -i ${IMPALA_HOST} -d ${KUDU_DATABASE} -q "$create_table_sql"
if [ $? -ne 0 ] ; then
  echo "${table_name}表创建失败"
else
  echo "${table_name}表创建成功"
fi
